
PACKAGE_NAME = board_games
MAJOR_VERSION = 1
MINOR_VERSION = 1
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION)

TOP_DIR := $(PWD)
#GAMES_FOLDER := "$(TOP_DIR)/games"

CFLAGS += -I$(TOP_DIR)/includes
CXXFLAGS += $(CFLAGS) -DMAJOR_VERSION=$(MAJOR_VERSION) -DMINOR_VERSION=$(MINOR_VERSION)

LDFLAGS += -L$(TOP_DIR)/src

PATH_TO_GAMES = $(wildcard games/*)
LIST_OF_GAMES := $(subst games/,,$(PATH_TO_GAMES))
#Exceptions
LIST_OF_GAMES := $(subst Makefile,,$(LIST_OF_GAMES))     
LIST_OF_GAMES := $(subst rules.mk,,$(LIST_OF_GAMES))  

all: framework tournament $(LIST_OF_GAMES)


$(LIST_OF_GAMES): common_sdk
	$(MAKE) -C games/$@

LIST_OF_GAME_CLEAN := $(patsubst %,%-clean, $(LIST_OF_GAMES))

$(LIST_OF_GAME_CLEAN): 
	$(MAKE) -C games/$(patsubst %-clean,%, $@) clean

	
tournament framework:
	$(MAKE) -C src $@
	mv src/$@ $(TOP_DIR)

framework-clean:
	$(MAKE) -C src clean

common_sdk:
	$(MAKE) -C src common_sdk
	
	

games: $(LIST_OF_GAMES)

	
games-clean:
	$(MAKE) -C games clean

clean: $(LIST_OF_GAME_CLEAN) framework-clean 
	rm -rf framework framework.* tournament tournament.exe $(PACKAGE_NAME)-$(VERSION).tgz

dist: clean
	rm -rf /tmp/$(PACKAGE_NAME)	
	mkdir /tmp/$(PACKAGE_NAME)
	cp -r * /tmp/$(PACKAGE_NAME)
	find /tmp/$(PACKAGE_NAME)/. | grep .svn | xargs rm -rf
	tar -C /tmp/ -zcvf $(TOP_DIR)/$(PACKAGE_NAME)-$(VERSION).tgz board_games
	rm -rf /tmp/$(PACKAGE_NAME)

.SILENT: help


help:
	echo ""	
	echo "To build all just type make"
	echo "To build an specific module type make followed by the module name"
	echo "Example:"
	echo "$> make games"
	echo
	echo "To clean all, type make followed by the target clean"
	echo "or <module name>-clean for individual module cleaning "
	echo 
	echo "Individual games can be compiled also specifying the output file"
	echo "For example:"
	echo $> make referee.so
	echo
	echo "To create the distributable package use make dist" 
	echo

export CFLAGS CXXFLAGS TOP_DIR LDFLAGS


.PHONY: help games framework-clean clean games-clean all common_sdk


